package com.hmall.order.web;

import com.hmall.common.dto.ResultDTO;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.RequestParams;
import com.hmall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单提交
     *
     * @param params
     * @return
     */
    @PostMapping("order")
    public Long createOrder(@RequestBody RequestParams params) {
        return orderService.createOrder(params);
    }

    /**
     * 模拟支付
     *
     * @param orderId
     * @param map
     * @return
     */
    @PutMapping("pay/{orderId}")
    public ResultDTO pay(@PathVariable("orderId") Long orderId, @RequestBody Map<String, String> map) {
        System.out.println(map);
        String password = map.get("password");
        return orderService.pay(orderId, password);
    }

    @GetMapping("order/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId) {
        return orderService.findOrderByOrderId(orderId);
    }


}
